#!/usr/bin/env python3
"""
核验记录数据模型
"""

from datetime import datetime

from sqlalchemy.orm import mapped_column, Mapped
from sqlalchemy.sql.sqltypes import Boolean, DateTime, Integer, String, Text

from app.models import Base


class VerificationRecord(Base):
    """核验记录表"""

    __tablename__ = "verification_records"

    # 主键
    id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)

    # 访客信息
    visitor_id: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="关联访客ID")
    visitor_name: Mapped[str] = mapped_column(String(100), nullable=False, comment="访客姓名")
    visitor_phone: Mapped[str | None] = mapped_column(String(20), nullable=True, comment="访客电话")
    visitor_type: Mapped[str] = mapped_column(
        String(20), 
        default="regular", 
        comment="访客类型: regular-普通, special-特殊, temporary-临时, vip-VIP"
    )
    special_visitor_flag: Mapped[bool] = mapped_column(Boolean, default=False, comment="特殊访客标志")

    # 核验信息
    qr_code_content: Mapped[str | None] = mapped_column(String(1000), nullable=True, comment="二维码内容")
    verify_time: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, comment="核验时间")
    verify_result: Mapped[str] = mapped_column(
        String(20), 
        default="pending", 
        comment="核验结果: pending-待审核, success-成功, reject-拒绝"
    )
    rejection_reason: Mapped[str | None] = mapped_column(Text, nullable=True, comment="拒绝原因")

    # 门卫信息
    guard_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="核验的门卫ID")
    guard_name: Mapped[str] = mapped_column(String(100), nullable=False, comment="核验的门卫姓名")
    guard_point: Mapped[str] = mapped_column(String(100), nullable=False, comment="核验点")

    # 关联信息
    related_audit_log_id: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="关联的审计日志ID")

    # 系统信息
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, comment="创建时间")

    def __repr__(self) -> str:
        return f"<VerificationRecord(id={self.id}, visitor_name='{self.visitor_name}', verify_result='{self.verify_result}')>"